home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: oasis.enmu.edu!cashew!reinholj
- From: reinholj@math.enmu.edu (John Reinhold)
- Subject: BORLAND C++ 4.5 wont add .1 and .9
- Sender: news@oasis.enmu.edu (All The News Fit To Print)
- Message-ID: <1996Jan18.044900.10609@oasis.enmu.edu>
- Date: Thu, 18 Jan 1996 04:49:00 GMT
- Organization: Eastern New Mexico University
- X-Newsreader: TIN [version 1.2 PL2]
-
- Borland C++ 4.5 won't add .1 + .9 to get 1.0
- This also does not work with negative numbers...
-
- Look at my source code, see if you see the problem.
-
- This all works unless you enter .01 or -.01,
- then it comes up with 0 and 0 which is incorrect.
-
- begin code:------------
- #include <stdio.h>
-
-
- float x = 0.0,rnd = 0.9;
- int ceiling = 0, floor = 0;
-
-
- main ()
- {
- /* */
- printf("Enter a number (n.n) EX: 4.5 \n");
- scanf("%f",&x);
-
- if (x<0.0)
- {
- ceiling=x;
- floor=x-rnd;
- }
- else
- {
- ceiling=x+rnd;
- floor=x;
- }
-
- printf("\n\nCeiling of %f is %d",x,ceiling);
- printf("\nFloor of %f is %d\n",x,floor);
-
- return 0;
-
-
- }
-
-
- end code:---------
-
- this program is supposed to find the ceiling and floor of a number...
- i.e. the ceiling of 1.5 is 2, and the floor is 1.
- the ceiling of -1.5 is -1 the floor is -2.
-
- The ceiling is right on the number line, floor is left.
-
- Thanks for any suggestions.
- By the way, making rnd 0.99 works (but only up to 1 decimal place).
-
- -john
-
- --
- ----------------------------<*>----------------------------
- TEAM OS/2
- At WARP speed, Windows should not be open.
-
- OAKLAND RAIDERS REAL MEN WEAR BLACK
- ++++++++++++++++++++++++++++<:>++++++++++++++++++++++++++++
- reinholj@mnw.net Montgomery, Alabama USA
- reinholj@math.enmu.edu Portales, New Mexico USA
- No Constitution, No Freedom. SUPPORT THE BILL OF RIGHTS.
- (NOT the Bill of Gates!)
-